package com.west_traveler.find_page_fragment.cate_fragment;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.west_traveler.entity.entity_category.entity_category_second.Entity_Cate_Fra_CategoryContents_Recom_Content;
import com.west_traveler.ximalayafm.R;
import com.west_traveler.ximalayafm.SecondRecommendActivity;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by Administrator on 12/12 0012.
 */

public class RecyclerAdapter_Cate_Single extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context context;
    private List<Entity_Cate_Fra_CategoryContents_Recom_Content> datas;


    public RecyclerAdapter_Cate_Single(Context context) {
        this.context = context;
        datas = new LinkedList<>();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.second_detial_item_recycle, parent, false);
        return new ViewHolderSingle(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Entity_Cate_Fra_CategoryContents_Recom_Content data = datas.get(position);
        if (holder instanceof ViewHolderSingle){
            ImageView iv_cover = ((ViewHolderSingle) holder).iv_cover;
            if (data.getCoverSmall()!=null&&!"".equals(data.getCoverSmall())){
                Picasso.with(context).load(data.getCoverSmall()).into(iv_cover);
            }

            ((ViewHolderSingle) holder).title_hot.setText(data.getTitle());
            ((ViewHolderSingle) holder).intro_hot.setText(data.getIntro());
            double d = data.getPlaysCounts();
            double v = d / 10000;
            ((ViewHolderSingle) holder).playsCounts_hot.setText(v+"万");
            ((ViewHolderSingle) holder).tracks_hot.setText(data.getTracks()+"集");
            ((ViewHolderSingle) holder).parent_hot.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent();
                    intent.putExtra("ID",data.getId()+"");
                    intent.putExtra("Title",data.getTitle());
                    intent.putExtra("PlaysCounts",data.getPlaysCounts()+"");
                    intent.putExtra("Nickname",data.getNickname());
                    intent.putExtra("CoverMiddle",data.getCoverMiddle());
                    intent.setClass(context,SecondRecommendActivity.class);
                    context.startActivity(intent);
                }
            });


        }
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    public int gettotalItemCount(){
        return getItemCount();
    }

    public void addAll(Collection<? extends Entity_Cate_Fra_CategoryContents_Recom_Content> collection) {
        int size = datas.size();
        datas.addAll(collection);
        notifyItemRangeInserted(size, collection.size());
    }

    public class ViewHolderSingle extends RecyclerView.ViewHolder{

        private final ImageView iv_cover;
        private final TextView title_hot;
        private final TextView intro_hot;
        private final TextView playsCounts_hot;
        private final TextView tracks_hot;
        private final View parent_hot;

        public ViewHolderSingle(View itemView) {
            super(itemView);
            parent_hot = itemView.findViewById(R.id.parent_detial);
            iv_cover = (ImageView) itemView.findViewById(R.id.iv_recomment_icon);
           title_hot = (TextView) itemView.findViewById(R.id.tv_title_big);
           intro_hot = (TextView) itemView.findViewById(R.id.tv_title_small);
            playsCounts_hot = (TextView) itemView.findViewById(R.id.iv_play_icon_value);
            tracks_hot = (TextView) itemView.findViewById(R.id.iv_collect_icon_value);

        }
    }
}
